<include file="Public/base"/>


<!--    <script type="text/javascript" src="__STATIC__/jquery-2.0.3.min.js"></script>
--> <!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.js"></script>
		    
<!--<script type="text/javascript" src="__STATIC__/jquery-1.8.2.min.js"></script>-->
<script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>

  <style type="text/css">
.txt-area{
display: block;
width: 100%;
height: 80px;
padding: 10px;
box-sizing: border-box;
margin-bottom: 5px;
}
#remaks-txt{
  margin-bottom: 20px;
}
        </style>

<script type="text/javascript">
		//点击x删除图片
		$(document).on('click','.del-img',function(){
			var liObj = $(this).parents('li');
			//找到父级li里面的地址
			var path = liObj.attr('path');
			var thumb = liObj.attr('thumb');
			//发异步到服务器删除
			$.ajax({
				type:"post",
				url:"{:U('/Admin/Good/Good/delImg')}",
				data:{path:path,thumb:thumb},
				success:function(data){
					//移除图片
					liObj.remove();
				}
				
			});
		})
		
		
		/*$('.del-img1').live('click',function(){alert($(this).index());
			var liObj = $(this).parents('span');
			//找到父级li里面的地址
			var path = liObj.attr('path');
			//发异步到服务器删除
			$.ajax({
				type:"post",
				url:"{|U:'delImg'}",
				data:{path:path},
				success:function(data){
					//移除图片
					liObj.remove();
				}
			});
		})*/
	</script>


<div class="pd-20">
    <form action="/Admin/Good/Good/add_data/type/add" method="post" class="form form-horizontal" id="addGoodForm">
        <div class="row cl">
            <label class="form-label col-3">商品编号</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="gid" value="" required minlength="2" maxlength="20"
                       id="good_id" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3">商品名称</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="name" value="" required minlength="2" maxlength="20"
                       id="good_name" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        <div class="row cl  uploadBox">
            <label class="form-label col-3">缩略图</label>
            <span class="btn-upload form-group" style="display:block">
                <!--<input class="input-text upload-url" type="text"  style="width:200px" value="上传"  >
                    <a href="javascript:;" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i>
                        上传商品图片</a>-->
                    <input type="file" value="上传图片"   name="pic" class="input-file" id="file">
            </span>
            <ul class="col-offset-3" style="padding-left: 0;">
            	
            </ul>
             
            
        </div>
        
        <script type="text/javascript">
	                $(function() {
	                	
	                    $('#file').uploadify({
	                    	'formData'    : {'session_id':'<?php echo session_id();?>'},
	                    	
	                        'fileTypeDesc' : '上传文件',//上传描述
	                        'fileTypeExts' : '*.jpg;*.png',
	                        'swf'      : '__STATIC__/uploadify/uploadify.swf',
	                        'uploader' :"<?php $str = $Think.ADMIN_PATH_NAME.$actions['GOODADDUPLOADIFY']['url'];echo U($str,array('key'=>$actions['GOODADDUPLOADIFY']['key']))?>",
	                        'buttonText':'选择文件',
	                        'fileSizeLimit' : '2000KB',
	                        'uploadLimit' : 11,//上传文件数
	                        'width':65,
	                        'height':25,
	                        'successTimeout':10,//等待服务器响应时间
	                        'removeTimeout' : 2,//成功显示时间
	                        'onUploadSuccess' : function(file, data, response) {
	                            data=$.parseJSON(data);
	                          //alert(data.thumb);
	                            var imageUrl = data.name?data.url:'__STATIC__/uploadify/uploadify-cancel.png';
	                            //alert(imageUrl);
	                            //alert(imageUrl);==data.url--http://localhost/yuxiang/uploadify_demo/Upload/Content/15/06/89101435416575.jpg
	                            var li="<li thumb='"+data.thumb+"' path='"+data.savepath+"' url='"+data.url+"'><img src='"+imageUrl+"' style='width:100px;heigth:100px;'/><a href='javascript:;' style='color:red' class='del-img'>X</a>";
	                            //把地址放到隐藏域，这样可以提交到服务器了
	                            /*$.each(data.tu,function(k,v){
	                            	li+="<span><img src='"+v+"' style='width:100px;heigth:100px;'/><a href='javascript:;' style='color:red' class='del-img1'>X</a></span>"
	                            })*/
	                            
	                            li += '<input type="hidden" name="thumb" value="'+data.thumb+'"/>';
	                            li += '<input type="hidden"  name="image" value="'+data.url+'"/>';
	                            li += '<input type="hidden"  name="pic" value="'+data.show+'"/>';
	                            
	                            li += '</li>';
    
                               $("div.uploadBox ul").prepend(li);
	                            //alert($("input[name=pic]").val());
	                        }
	                    });
	                });
	                
	            </script>
        
       
        <div class="row cl">
            <label class="form-label col-3">价格</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="price" value="{$goodInfo.price}" required minlength="2" maxlength="200"
                       id="good_price" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
       <div class="row cl">
            <label class="form-label col-3">状态</label>
             <div class="formControls col-xs-4 col-sm-4">
                <span class="select-box">
              <select class="select sex" size="1" name="is_valid" id="status">
            <option value="0">下架</option>
            <option value="1">上架</option>
                   
          </select>
        </span>
                   
                </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3">批准文号</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="approval_number" value="{$goodInfo.approval_number}" required minlength="2" maxlength="200"
                       id="good_approval" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
         <div class="row cl">
            <label class="form-label col-3">成分</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="ingredients" value="{$goodInfo.ingredients}" required minlength="2" maxlength="20"
                       id="good_ingredients" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
         <div class="row cl">
            <label class="form-label col-3">规格</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="specifications" value="{$goodInfo.specifications}" required minlength="2" maxlength="200"
                       id="good_specifications" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        
         <div class="row cl">
            <label class="form-label col-3">生产厂家</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="anufacturer" value="{$goodInfo.anufacturer}" required minlength="2" maxlength="200"
                       id="good_anufacturer" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-3">经营企业</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="enterprise" value="{$goodInfo.enterprise}" required minlength="2" maxlength="200"
                       id="good_enterprise" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        
         <div class="row cl">
            <label class="form-label col-3">主治功能</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="attending" value="{$goodInfo.attending}" required minlength="2" maxlength="200"
                       id="good_attending" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>
        <!--<div class="row cl">
            <label class="form-label col-3">用法用量</label>
            <div class="formControls col-5">
                <input type="text" class="input-text" name="usage" value="{$goodInfo.usage}" required minlength="2" maxlength="2000"
                       id="good_usage" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">
            </div>
        </div>-->
        <div class="row cl">
             <label class="form-label col-3">分类</label>
             <div class="formControls col-xs-4 col-sm-4">
                <span class="select-box">
              <select class="select sex" size="1" name="classify" id="classify">
               <option value="0">请选择</option>
               <volist name="classify" id="data">
               <option value="{$data.id}">{$data.classify}</option>
               </volist>
          </select>
        </span>
                   
                </div>
        </div>
          <div class="row cl" id="children">
           
        </div>
        <div class="row cl">
            <label class="form-label col-3">用法用量</label>
            <div class="formControls col-5">
                
                       <textarea id="remaks-txt" name="usage" value="{$goodInfo.usage}" class="remaks-txt txt-area" resize="none" value="" placeholder="最多2000字"></textarea>

            </div>
        </div>
        
         
    
        <div class="row cl">
            <label class="form-label col-3">优势</label>
            <div class="formControls col-5">
                <!--<input type="text" class="input-text" name="advantage" value="{$goodInfo.advantage}" required minlength="2" maxlength="2000"
                       id="drugs_advantage" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">-->
                        <textarea id="adv-txt" name="advantage"  class="dv-txt txt-area" resize="none" value="{$goodInfo.advantage}" placeholder="最多100字"></textarea>

            </div>
        </div>
         <div class="row cl">
            <label class="form-label col-3">备注</label>
            <div class="formControls col-5">
                <!--<input type="text" class="input-text" name="remark" value="{$goodInfo.remark}" required minlength="2" maxlength="2000"
                       id="drugs_remark" _target="{:U($Think.ADMIN_PATH_NAME.'Good/NRLable/checkLable')}">-->
                       <textarea id="remaks-txt" name="remark" value="{$goodInfo.remark}" class="remaks-txt txt-area" resize="none" value="" placeholder="最多100字"></textarea>

            </div>
        </div>
       
       
       
        
         </form>
        <div class="row cl">
            <div class="col-9 col-offset-3">
                <button class="btn btn-primary radius" id="submit" type="button">确 定
                </button>
                <button class="btn btn-warning radius" onclick="history.back(-1);return false;">返 回</button>
            </div>
        
        
</div>

<script>
	$(function(){
	
          $("#classify").change(function(){
            var val = $(this).val();
            val = parseInt(val);
            if(val!==0)
            {
                $.ajax({
                    type:"POST",
                    url:"/Admin/Good/Good/add/type/change/key/GOODADD",
                    data:"id="+val,
                    dataType: "json",
                    success:function(msg)
                    {
                      
                      if(msg.status==1)
                      {
                          var str = '<label class="form-label col-3 ">二级分类</label>';
                          str+='<div class="formControls col-xs-4 col-sm-4">';
                          str+=' <span class="select-box">';
                          str+='<select class="select sex" size="1" name="classify_new" id="classify">';
                          for(var i=0;i<msg.message.length;i++)
                          {
                             str+='<option value='+msg.message[i].id+'>'+msg.message[i].classify+'</option>';
                          }
                          str+='</select></span></div></div>';
                          $("#children").html("");
                         $("#children").append(str);
                      }
                    }
                })
            }
          })
       
		
		$("#submit").click(function(){
    
			$.ajax({
              type:"POST",
              url:"/Admin/Good/Good/add/type/add/key/GOODADD",
              data:$("#addGoodForm").serialize(),
              success:function(msg)
              {
                   if(msg.status==1)
                   {
              	   window.alert(msg.message);
              	   window.location.href="/Admin/Good/Good/index/key/GOODLIST.html";
                 }else{
                    window.alert(msg.message);
                 }
              }

			})
			
			
		})

	})
</script>

<!--<script src="__JS__/Good/lable.js"></script>-->
